
<template>
  <!-- 新增产品 -->
  <div class="AddProduct">
    <div class="side_1"></div>
    <span class="add_1">编辑产品</span>
    <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Fh">返回</el-button>
    <div class="content">
      <div class="head">
        <div class="lt">
          <span>产品信息</span>
        </div>
        <div class="form_pro">
          <el-row :gutter="10">
            <el-col :span="5">
              <el-form :model="formInlines" class="demo-form-inline" label-width="80px">
                <el-form-item label="产品名称">
                  <el-input v-model="formInlines.productname"></el-input>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="5">
              <el-form :model="formInlines" class="demo-form-inline" label-width="80px">
                <el-form-item label="产品编号">
                  <el-input v-model="formInlines.productno"></el-input>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="8">
              <el-form :model="formInlines" class="demo-form-inline" label-width="80px">
                <el-form-item label="产品类型">
                  <el-select v-model="formInlines.producttype" placeholder="请选择" style="wdith:80%">
                    <el-option
                      v-for="item in options"
                      :key="item.no"
                      :label="item.name"
                      :value="item.name"
                    ></el-option>
                  </el-select>
                  <el-button class="add" size="medium" type="primary" @click="addtype">新增</el-button>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="5">
              <el-form :model="formInlines" class="demo-form-inline" label-width="80px">
                <el-form-item label="产品型号">
                  <el-input v-model="formInlines.productmodel"></el-input>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="5">
              <el-form :model="formInlines" class="demo-form-inline" label-width="80px">
                <el-form-item label="图纸编号">
                  <el-input v-model="formInlines.drawingsno"></el-input>
                </el-form-item>
              </el-form>
            </el-col>

            <el-col :span="5">
              <el-form :model="formInlines" class="demo-form-inline" label-width="80px">
                <el-form-item label="产品描述">
                  <el-input v-model="formInlines.describe"></el-input>
                </el-form-item>
              </el-form>
            </el-col>

            <el-col :span="8">
              <el-form :model="formInlines" class="demo-form-inline" label-width="80px">
                <el-form-item label="计量单位">
                  <el-input v-model="formInlines.unit">米</el-input>
                  <el-checkbox v-model="checked">作为计量标准</el-checkbox>
                </el-form-item>
              </el-form>
            </el-col>
          </el-row>
        </div>
      </div>
      <div class="body">
        <div class="left">
          <div class="lt">
            <span>产品图片</span>
          </div>
          <div class="form-left">
            <el-upload
              class="avatar-uploader"
              action="/apis/PublicAPI.asmx/UpImg"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl" :src="imageUrl" class="avatar" />
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </div>
        </div>
        <div class="middle">
          <div class="lt">
            <span class="span">检具信息</span>
          </div>
          <div class="form_left">
            <el-form :ref="form" :model="formss" :inline="true" class="demo-form-inline">
              <el-form-item label="数量[套]" style="width:55%">
                <el-input v-model="formss.jianjushuliang"></el-input>
              </el-form-item>
              <el-form-item label="承制方" style="width:40%">
                <el-input v-model="formss.chengzhifang"></el-input>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="right">
          <div class="lt">
            <span>产品图纸</span>
          </div>
          <div class="form-left">
            <el-upload
              class="avatar-uploader"
              action="/apis/PublicAPI.asmx/UpImg"
              :show-file-list="false"
              :on-success="handleAvatarSuccess2"
              :before-upload="beforeAvatarUpload"
            >
              <img v-if="imageUrl2" :src="imageUrl2" class="avatar" />
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </div>
        </div>
      </div>
      <div class="kuang_3">
        <div class="lt">
          <span>制件信息</span>
        </div>

        <div class="form_pro">
          <el-form :inline="true" :model="formInline_z" class="demo-form-inline" label-width="80px">
            <div class="f1">
              <el-form-item label="序号">
                <el-input v-model="formInline_z.xuhao"></el-input>
              </el-form-item>
              <el-form-item label="整车用件">
                <el-input v-model="formInline_z.yongjian"></el-input>
              </el-form-item>
            </div>
            <div class="f2">
              <el-form-item label="料厚">
                <el-input v-model="formInline_z.liaohou"></el-input>
              </el-form-item>
              <el-form-item label="长">
                <el-input v-model="formInline_z.chang"></el-input>
              </el-form-item>
            </div>
            <div class="f3">
              <el-form-item label="制件重量">
                <el-input v-model="formInline_z.height"></el-input>
              </el-form-item>

              <el-form-item label="宽">
                <el-input v-model="formInline_z.kuan"></el-input>
              </el-form-item>
            </div>
            <div class="f4">
              <el-form-item label="整车用量">
                <el-input v-model="formInline_z.yongliang"></el-input>
              </el-form-item>
              <el-form-item label="高">
                <el-input v-model="formInline_z.gao"></el-input>
              </el-form-item>
            </div>
          </el-form>
        </div>
      </div>

      <div class="body">
        <div class="bot-left">
          <div class="lt">
            <span>原料信息</span>
          </div>
          <el-table :data="tableData" height="180">
            <el-table-column align="center" type="index" label="序号" prop="xuhao"></el-table-column>
            <el-table-column align="center" label="原料名称">
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.rawname"
                  placeholder="请选择"
                  @change="yuanliaoname(scope)"
                  style="width:90px"
                >
                  <el-option
                    v-for="item in optionss"
                    :key="item.no"
                    :label="item.name"
                    :value="item"
                  ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column align="center" label="原料料号">
              <template slot-scope="scope">
                <el-input v-model="scope.row.rawno" style="width:80px"></el-input>
              </template>
            </el-table-column>
            <el-table-column align="center" label="原料数量">
              <template slot-scope="scope">
                <el-input v-model="scope.row.number" style="width:80px"></el-input>
              </template>
            </el-table-column>
            <el-table-column align="center" label="领料率">
              <template slot-scope="scope">
                <el-input v-model="scope.row.lingliaolv" style="width:80px"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  v-show="scope.$index == 0"
                  size="small"
                  :type="aaa"
                  @click="caozuo(scope)"
                >新增</el-button>
                <el-button
                  size="small"
                  v-show="scope.$index !== 0"
                  :type="bbb"
                  @click="caozuo(scope)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>

        <div class="bot-right">
          <div class="lt">
            <span>模具信息</span>
          </div>

          <el-table :data="tableDatas" height="180">
            <el-table-column align="center" type="index" label="序号" prop="xuhao"></el-table-column>
            <el-table-column align="center" label="模具名称">
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.mouldname"
                  placeholder="请选择"
                  @change="mujuname(scope)"
                  style="width:80px"
                >
                  <el-option
                    v-for="item in optionsss"
                    :key="item.no"
                    :label="item.name"
                    :value="item"
                  ></el-option>
                </el-select>
              </template>
            </el-table-column>

            <el-table-column align="center" label="长">
              <template slot-scope="scope">
                <el-input v-model="scope.row.chang" style="width:60px"></el-input>
              </template>
            </el-table-column>
            <el-table-column align="center" label="宽">
              <template slot-scope="scope">
                <el-input v-model="scope.row.kuan" style="width:60px"></el-input>
              </template>
            </el-table-column>
            <el-table-column align="center" label="高">
              <template slot-scope="scope">
                <el-input v-model="scope.row.gao" style="width:60px"></el-input>
              </template>
            </el-table-column>
            <el-table-column align="center" label="数量">
              <template slot-scope="scope">
                <el-input v-model="scope.row.number" style="width:60px"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  v-show="scope.$index == 0"
                  size="small"
                  :type="aaa"
                  @click="caozuo_1(scope)"
                >新增</el-button>
                <el-button
                  size="small"
                  :type="bbb"
                  v-show="scope.$index !== 0"
                  @click="caozuo_1(scope)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>

      <div class="bottom">
        <div class="lt">
          <span>工序流程</span>
        </div>
        <div class="el-table-bot">
          <el-table :data="tableDatass" height="500">
            <el-table-column align="center" label="工序">
              <template slot-scope="scope">
                <el-input v-model="scope.row.steps" style="width:120px"></el-input>
              </template>
            </el-table-column>

            <el-table-column align="center" label="工艺名称">
              <template slot-scope="scope">
                <el-input v-model="scope.row.processname" style="width:120px" @blur="add(scope)"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  v-show="scope.$index == 0"
                  size="small"
                  :type="aaa"
                  @click="caozuo_2(scope)"
                >新增</el-button>
                <el-button
                  size="small"
                  v-show="scope.$index !== 0"
                  :type="bbb"
                  @click="caozuo_2(scope)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <el-dialog
        :visible.sync="dialogVisible"
        width="75%"
        style="margin-left:45%"
        :modal-append-to-body="false"
        :close-on-click-modal="false"
      >
        <div class="lt">
          <span>基本信息</span>
        </div>
        <div class="el-form-bot">
          <el-row :gutter="10">
            <el-col :span="10">
              <el-form :model="formInlines_1" class="demo-form-inline" label-width="80px">
                <el-form-item label="工艺名称">
                  <el-input v-model="formInlines_1.processname" style="width:95%"></el-input>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="10">
              <el-form :model="formInlines_1" class="demo-form-inline" label-width="80px">
                <el-form-item label="领料类型">
                  <el-input v-model="formInlines_1.lingliaotype" style="width:95%"></el-input>
                </el-form-item>
              </el-form>
            </el-col>

            <el-col :span="10">
              <el-form :model="formInlines_1" class="demo-form-inline" label-width="80px">
                <el-form-item label="时产能">
                  <el-input v-model="formInlines_1.shichanneng" style="width:95%"></el-input>
                </el-form-item>
              </el-form>
            </el-col>

            <el-col :span="10">
              <el-form :model="formInlines_1" class="demo-form-inline" label-width="80px">
                <el-form-item label="报废率">
                  <el-input v-model="formInlines_1.baofeilv" style="width:95%"></el-input>
                </el-form-item>
              </el-form>
            </el-col>

            <el-col :span="10">
              <el-form :model="formInlines_1" class="demo-form-inline" label-width="80px">
                <el-form-item label="设备类型">
                  <el-select
                    v-model="formInlines_1.equiptype"
                    placeholder
                    style="width:95%"
                    @change="Equip"
                  >
                    <el-option
                      v-for="item in option_s"
                      :key="item.no"
                      :label="item.name"
                      :value="item.name"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="10">
              <el-form :model="formInlines_1" class="demo-form-inline" label-width="80px">
                <el-form-item label="设备名称">
                  <el-select
                    v-model="formInlines_1.equipname"
                    placeholder
                    style="width:95%"
                    @change="EquipName"
                  >
                    <el-option
                      v-for="item in option_m"
                      :key="item.no"
                      :label="item.name"
                      :value="item.no"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="10">
              <el-form :model="formInlines_1" class="demo-form-inline" label-width="80px">
                <el-form-item label="注意事项">
                  <el-input v-model="formInlines_1.zysx" type="textera" style="width:270%;"></el-input>
                </el-form-item>
              </el-form>
            </el-col>
          </el-row>
        </div>
        <div class="lt_1">
          <span>原料信息</span>
        </div>

        <div id="table_bot">
          <el-table :data="tableData_yl" height="150">
            <el-table-column align="center" type="index" label="序号" prop="xuhao"></el-table-column>

            <el-table-column align="center" label="原料名称">
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.rawname"
                  placeholder="请选择"
                  @change="yuanliaoname_1(scope)"
                  style="width:90px"
                >
                  <el-option
                    v-for="item in optionss"
                    :key="item.no"
                    :label="item.name"
                    :value="item"
                  ></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column align="center" label="原料料号">
              <template slot-scope="scope">
                <el-input v-model="scope.row.rawno" style="width:90px"></el-input>
              </template>
            </el-table-column>
            <el-table-column align="center" label="原料数量">
              <template slot-scope="scope">
                <el-input v-model="scope.row.number" style="width:90px"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  v-show="scope.$index == 0"
                  size="small"
                  :type="aaa"
                  @click="caozuo_3(scope)"
                >新增</el-button>
                <el-button
                  size="small"
                  v-show="scope.$index !== 0"
                  :type="bbb"
                  @click="caozuo_3(scope)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="footer">
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="save">保 存</el-button>
          </span>
        </div>
      </el-dialog>

      <!-- 新增类别 -->
      <el-dialog
        title="新增类别"
        :visible.sync="dialogVisibless"
        width="300px"
        :modal-append-to-body="false"
        :close-on-click-modal="false"
      >
        <div class="color_box"></div>
        <div class="contents">
          <el-form ref="form" :model="forms" label-width="60px">
            <el-form-item label="类别">
              <el-input v-model="forms.yname"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <div class="footer">
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="saveDia">保 存</el-button>
          </span>
        </div>
      </el-dialog>
    </div>
    <div class="btn_bottom">
      <el-button type="primary" size="medium" @click="Edit">确定</el-button>
      <el-button type="info" size="medium" @click="quXiao">返回</el-button>
    </div>
  </div>
</template>


<script>
import axios from "axios";
export default {
  data() {
    return {
      dialogVisible: false,
      leibie: {},

      dialogVisibless: false,

      imageUrl2: "",
      formInlines: {},
      formInlines_1: {
          processname:'',
        lingliaotype: "",
      equiptype:'',
      equipname:'',
      zysx:'',
      shichanneng:'',
      baofeilv:'',
      },
      formInline_z: {},
      checked: "true",
      imageUrl: "",
      options: [],
      optionss: [],
      optionsss: [],

      producttype: "",

      form: {
        model: ""
      },
      forms: {
        yname: ""
      },
      formss: {},
      tableData: [
        {
          xuhao: "",
          rawname: "",
          rawno: "",
          number: "",
          lingliaolv: ""
        }
      ],
      tableDatas: [
        {
          xuhao: "1",
          mouldname: "",
          chang: "",
          kuan: "",
          gao: "",
          number: ""
        }
      ],
      tableDatass: [
        {
          steps: "",
          processname: ""
        }
      ],

      tableData_yl: [
        {
            xuhao:'1',
          rawname: "",
          number: "",
          rawno: ""
        }
      ],

      option_s: [],
      type: [],

      option_m: [],

      //新增删除按钮颜色
      aaa: "primary",
      bbb: "info",
      Id: "",
      Ides: "",
      Leibie: "",    //新增类别使用
      equiptype: "",
      Leibie: "",
      mouldno: "",
      datas: [],
      datas2: [],
      index: "",
      stepss: "",  //工序Id
      Idss: "",   //弹框原料信息Id
      IdJB:'',   //基本信息Id
      IdYL:'',  //原料Id
      IdMJ:'',  //编辑模具Id,
      Idyl:'', //弹框原料信息
    };
  },
  created() {
    this.Id = this.$route.query.idss;
    this.getDetail();
    this.Ides = this.$route.query.ides;
    this.getlist(); //产品类别下拉选

    this.getlist1();
    this.getlist2();
    this.getlist4();

    this.getlist6();
  },

  methods: {
    //获取产品类别下拉选
    getlist() {
      axios("/apis/ProductManagement.asmx/Get?index=3&jsondata=").then(
        ({ data }) => {
          var datas = this.$x2js.xml2js(data);
          console.log(datas);
          var list = JSON.parse(datas.string.__text);
          //console.log(list);
          this.options = list;
        }
      );
    },
    //原料名称下拉选
    getlist1() {
      axios("/apis/ProductManagement.asmx/Get?index=5&jsondata=").then(
        ({ data }) => {
          var datas = this.$x2js.xml2js(data);
          console.log(datas);
          var list = JSON.parse(datas.string.__text);
          console.log(list);
          this.optionss = list;
        }
      );
    },
    //原料名称下拉选
    yuanliaoname(e) {
      console.log(e);
      this.tableData[e.$index].rawno = e.row.rawname.no;
      this.tableData[e.$index].rawname = e.row.rawname.name;

      // this.tableData_yl[e.$index].rawno=e.row.rawname.no;
      // console.log(this.tableData[e.$index].rawno)
    },
    //底部原料名称下拉选
    yuanliaoname_1(e) {
      this.tableData_yl[e.$index].rawno = e.row.rawname.no;

      this.tableData_yl[e.$index].rawname = e.row.rawname.name;
    },
    //工艺名称
    //     getlist3(){
    //    axios("/apis/ProductManagement.asmx/Get?index=5&jsondata=").then(
    //     ({ data }) => {
    //       var datas = this.$x2js.xml2js(data);
    //       console.log(datas);
    //       var list = JSON.parse(datas.string.__text);
    //        console.log(list);
    //      this.optionss=list;

    //     }
    //   )
    //  },
    // 模具名称下拉选
    getlist2() {
      axios("/apis/ProductManagement.asmx/Get?index=6&jsondata=").then(
        ({ data }) => {
          var datas = this.$x2js.xml2js(data);
          console.log(datas);
          var list = JSON.parse(datas.string.__text);
          //console.log(list);
          this.optionsss = list;
        }
      );
    },
    mujuname(e) {
      console.log(e);
      this.mouldno = e.row.mouldname.no;
      this.tableDatas[e.$index].mouldname = e.row.mouldname.name;
      console.log(this.mouldno);
      console.log(this.tableDatas[e.$index].mouldname);
    },
    //设备类型
    getlist4() {
      axios("/apis/ProductManagement.asmx/Get?index=1&jsondata=").then(
        ({ data }) => {
          var datas = this.$x2js.xml2js(data);
          console.log(datas);
          var list = JSON.parse(datas.string.__text);
          // console.log(list);
          this.option_s = list;
        }
      );
    },
    Equip(e) {
      // console.log(e)
      this.equiptype = e;
      console.log(this.equiptype);
      this.getlist5();
    },
    //设备名称
    getlist5() {
      axios(
        "/apis/ProductManagement.asmx/Get?index=2&jsondata=" + this.equiptype
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        console.log(datas);
        var list = JSON.parse(datas.string.__text);
        console.log(list);
        this.option_m = list;
      });
    },
    //
    EquipName(e) {
      this.equipno = e;
      console.log(this.equipno);
    },
    //领料类型
    getlist6() {
      // axios("/apis/ProductManagement.asmx/Get?index=7&jsondata=").then(
      //       ({ data }) => {
      //         var datas = this.$x2js.xml2js(data);
      //         console.log(datas);
      //         var list = JSON.parse(datas.string.__text);
      //          console.log(list);
      //        this.type=list;
      //       }
      //     )
    },

    Fh() {
      window.history.go(-1);
    },
    quXiao() {
      window.history.go(-1);
    },
    //  新增产品类型弹框
    addtype() {
      this.dialogVisibless = true;
    },
    saveDia() {
      this.Leibie = this.forms.yname;
      //var objs=JSON.stringify(obj);
      axios(
        "/apis/ProductManagement.asmx/Get?index=4&jsondata=" + this.Leibie
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        console.log(datas);
        if (datas.string.__text == "SUCCESS") {
          this.$message.success("保存成功");
          this.dialogVisibless = false;
          this.getlist()
        } else {
          this.$message.error(datas.string.__text);
        }
      });
    },

    //获取详情信息
    //产品详情
    getDetail() {
      axios(
        "/apis/ProductManagement.asmx/Det_Product?index=1&jsondata=" + this.Id
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        console.log(datas);
        var list = JSON.parse(datas.string.__text);
        console.log(list);
        //产品信息

        this.formInlines = list.product_det;

        this.formInlines.productname = this.$route.query.proname;
        this.formInlines.producttype = this.$route.query.protype;
        this.formInlines.unit = this.$route.query.unit;
        //   //弹框
        // this.formInline=list.sour1;

        //     //产品图片
        this.imageUrl = list.product_det.picpath;
        //     //产品图纸
        this.imageUrl2 = list.product_det.drawingspath;
        //检具信息
        this.formss = list.product_det;
        //制件信息
        this.formInline_z = list.product_det;
        //原料信息
        this.tableData = list.raws;

        //模具信息
        this.tableDatas = list.moulds;
        //工艺流程
        this.tableDatass = list.processes;
        //弹框
      });
    },

    //编辑

    // 基本信息 原料信息弹框
    add(e) {
      this.dialogVisible = true;
   
      console.log(e);

      //  console.log(this.datas[e.$index].steps)
      //  this.datas2[e.$index].steps=e.row.steps;
      this.index = e.$index;
    //   console.log(e.$index);
    //   console.log(e.row.steps);
      var obj = {
        productno: this.Id,
        steps: e.row.steps
      };
      var objs = JSON.stringify(obj);
      axios(
        "/apis/ProductManagement.asmx/Det_Product?index=11&jsondata=" + objs
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        // console.log(datas);
        var list = JSON.parse(datas.string.__text);
         console.log(list);
         if(list.mess===null){
             this.formInlines_1={}
         }else{
        this.formInlines_1 = list.mess;
        }
if(list.raws.length===0){
    this.tableData_yl=[
        {
            xuhao:'1',
          rawname: "",
          number: "",
          rawno: ""
        }
      ]

}else{
this.tableData_yl = list.raws;
}
     
      });
      this.stepss = e.row.steps;
           

     this.formInlines_1.processname = e.row.processname;
      
    },

    save() {
      this.dialogVisible = false;
      //基本信息
      var obj = {
        steps: this.stepss,
        Id:this.formInlines_1.Id,
        processname: this.formInlines_1.processname,
        lingliaotype: this.formInlines_1.lingliaotype,
        shichanneng: this.formInlines_1.shichanneng,
        baofeilv: this.formInlines_1.baofeilv,
        equiptype: this.formInlines_1.equiptype,
        equipname: this.formInlines_1.equipname,

        equipno: this.equipno,

        zysx: this.formInlines_1.zysx
      };
      //底部原料信息
      var arr = [];
      for (var i = 0; i < this.tableData_yl.length; i++) {
        var obj4 = {
          Id:this.tableData_yl[i].Id,
          steps: this.stepss,
          rawname: this.tableData_yl[i].rawname,
          rawno: this.tableData_yl[i].rawno,
          number: this.tableData_yl[i].number
        };
        arr.push(obj4);
      }

      this.datas2[this.index] = arr;

      this.datas[this.index] = obj;
    },

    //上传产品图片
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
      console.log(this.imageUrl);
      var datas = this.$x2js.xml2js(res);
      console.log(datas);
      this.imageUrl11 = datas.UpFileReturn.fullurl;
    },
    //上传产品图纸
    handleAvatarSuccess2(res, file) {
      this.imageUrl2 = URL.createObjectURL(file.raw);
      var datas = this.$x2js.xml2js(res);
      console.log(datas);
      this.imageUrl22 = datas.UpFileReturn.fullurl;
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isLt2M;
    },
     // 原料信息 新增
    caozuo(e) {
      console.log(e);

      if (e.$index == 0) {
        var list = {
          rawname: "",
          rawno: "",
          number: "",
          linagliaolv: "",
      
        };
        this.tableData.push(list);
      } else {
    //原料信息删除接口  
        axios(
          "/apis/ProductManagement.asmx/Save_Product?index=12&jsondata=" + e.row.Id
        ).then(({ data }) => {
           var datas = this.$x2js.xml2js(data);
          console.log(datas);
           if (datas.string.__text == "SUCCESS") {
              this.tableData.splice(e.$index, 1);
           }else{
               this.$message.error(datas.string.__text)
           }
        }
        )
      }
    },

    // 模具信息新增 
    caozuo_1(e) {
  console.log(e)
      if (e.$index == 0) {
        var list = {
          xuhao: "",
          chang: "",
          kuan: "",
          gao: "",
          number: "",
        
        };
        this.tableDatas.push(list);
      } else {
//模具信息删除接口
        axios(
          "/apis/ProductManagement.asmx/Save_Product?index=14&jsondata=" + e.row.Id
        ).then(({ data }) => {
          var datas = this.$x2js.xml2js(data);
          console.log(datas);
           if (datas.string.__text == "SUCCESS") {
              this.tableDatas.splice(e.$index, 1);
           }else{
               this.$message.error(datas.string.__text)
           }
        
      }
        )
      }
        
    },
    // 工艺流程 新增
    caozuo_2(e) {
        console.log(e)
      if (e.$index == 0) {
        var list = {
          steps: "",
          processname: ""
        };
        this.tableDatass.push(list);
      } else {
    //       var obj={
    //     //   process:{ Id:id } process_mess:{ Id:id } process_rawList:[{ Id:id }]
    //       }

    //   var objs = JSON.stringify(obj);
    //工序删除接口
           axios(
          "/apis/ProductManagement.asmx/Save_Product?index=16&jsondata=" + e.row.Id
        ).then(({ data }) => {
          var datas = this.$x2js.xml2js(data);
          console.log(datas);
          if (datas.string.__text == "SUCCESS") {
              this.tableDatass.splice(e.$index, 1);
           }else{
               this.$message.error(datas.string.__text)
           }
        }
        )
      
       
      }
    },
    // 动态添加底部 右侧
    caozuo_3(e) {
        console.log(e)
     
      if (e.$index == 0) {
        var list = {
          rawname: "",
          number: "",
          rawno: ""
        };
        this.tableData_yl.push(list);
      } else {
//弹框-原料信息 删除接口  

         axios(
          "/apis/ProductManagement.asmx/Save_Product?index=160&jsondata=" + e.row.Id
        ).then(({ data }) => {
          var datas = this.$x2js.xml2js(data);
          console.log(datas);
          if (datas.string.__text == "SUCCESS") {
              this.tableData_yl.splice(e.$index, 1);
           }else{
               this.$message.error(datas.string.__text)
           }
        }
        )
      }
    },
  
    //新增产品  确定即保存
    Edit() {
      //产品信息
     var product={}
       product.productno = this.formInlines.productno;
       product.productname=this.formInlines.productname;
       product.producttype=this.formInlines.producttype;
       product.productmodel=this.formInlines.productmodel;
       product.unit=this.formInlines.unit;
       product.describe=this.formInlines.describe;
       product.drawingsno=this.formInlines.drawingsno;

      //工序数
      product.processnumber = this.tableDatass.length;

      //产品图片
      product.picpath = this.imageUrl11;
      product.picpath2 = this.imageUrl;
      //产品图纸
      product.drawingspath = this.imageUrl22;
      product.drawingspath2 = this.imageUrl2;
      //检具信息
      product.jianjushuliang = this.formss.jianjushuliang;
      product.chengzhifang = this.formss.chengzhifang;

      //制件信息
      product.xuhao = this.formInline_z.xuhao;
      product.liaohou = this.formInline_z.liaohou;
      product.height = this.formInline_z.height;
      product.yongliang = this.formInline_z.yongliang;
      product.yongjian = this.formInline_z.yongjian;
      product.chang = this.formInline_z.chang;
      product.kuan = this.formInline_z.kuan;
      product.gao = this.formInline_z.gao;

      //原料信息
     
    
      var list = this.tableData;
     
      var arr = [];
      for (var i = 0; i < list.length; i++) {
        var obj1 = {
        Id:list[i].Id,
        
          rawname: list[i].rawname,
          rawno: list[i].rawno,
          number: list[i].number,
          lingliaolv: list[i].lingliaolv
        };
        arr.push(obj1);
      }
      console.log(arr);
  
      //模具信息
      var lists = this.tableDatas;
      var arr1 = [];
      for (var i = 0; i < lists.length; i++) {
        var obj2 = {
            Id: lists[i].Id,
          mouldno: this.mouldno,
          mouldname: lists[i].mouldname,
          chang: lists[i].chang,
          kuan: lists[i].kuan,
          gao: lists[i].gao,
          number: lists[i].number
        };
        arr1.push(obj2);
      }
      console.log(arr1);
      //工艺流程
      var listss = this.tableDatass;
      var arr2 = [];
      for (var i = 0; i < listss.length; i++) {
        var obj3 = {
          Id: listss[i].Id,
          steps: listss[i].steps,
          processname: listss[i].processname
        };
        arr2.push(obj3);
      }
      console.log(arr2);

      var obj = {
        product: product,
        product_raws: arr,
        moulds: arr1,
        process: arr2,
        process_mess: this.datas,
        process_rawList: this.datas2
      };

      var objs = JSON.stringify(obj);
      console.log(objs);
      axios(
        "/apis/ProductManagement.asmx/Save_Product?index=10&jsondata=" + objs
      ).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        console.log(datas);
        if (datas.string.__text == "SUCCESS!") {
          this.$message.success("保存成功");
          window.history.go(-1);
        } else {
          this.$message.error(datas.string.__text);
        }
      });
    },

    
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/base.scss";
.content {
  width: 100%;
  height: 700px;
  overflow: auto;
}
.side_1 {
  width: 5px;
  height: 16px;
  background-color: $Header_color;
  margin-left: 10px;
  margin-top: 20px;
}
.add_1 {
  margin-left: 20px;
  margin-top: -20px;
  float: left;
  font-size: 18px;
  font-weight: 400;
}
.btn_fanhui {
  margin-top: -20px;
  margin-right: 20px;
  float: right;
}
.head {
  width: 98%;
  height: 250px;
  background-color: $white;
  margin-left: 10px;
  margin-top: 30px;
  overflow: hidden;
  border: 1px solid $bordercolor;
  margin-bottom: 20px;
  border-radius: 5px;
}
.color_box {
  width: 5px;
  height: 20px;
  background-color: $Header_color;
  position: absolute;
  top: 22px;
  left: 10px;
}
.body {
  overflow: hidden;
  margin-bottom: 10px;
  margin-left: 10px;
  width: 98%;
}
.left {
  background-color: $white;
  display: inline-block;
  border-radius: 5px;
  width: 20%;
  height: 300px;
  border: 1px solid $bordercolor;
}
.middle {
  background-color: $white;
  // display: inline-block;
  float: right;
  border-radius: 5px;
  width: 56%;
  height: 300px;
  border: 1px solid $bordercolor;
  margin-left: 15px;
}
.right {
  width: 20%;
  float: right;
  //display: inline-block;
  background-color: $white;
  border-radius: 5px;
  height: 300px;
  border: 1px solid $bordercolor;
}
.lt {
  height: 60px;
  line-height: 60px;
  width: 90%;
  margin-left: 20px;
  border-bottom: 1px solid $bordercolor;
  margin-bottom: 40px;
  font-family: "微软雅黑 Bold", "微软雅黑 Regular", "微软雅黑";
  font-weight: bold;
  font-style: normal;
  font-size: 14px;
}
.lt .span {
  margin-left: 20px;
}
.bot-left {
  background-color: $white;
  display: inline-block;
  border-radius: 5px;
  width: 48%;
  height: 280px;
  border: 1px solid $bordercolor;
}
.bot-right {
  width: 51%;
  float: right;
  background-color: $white;
  border-radius: 5px;
  height: 280px;
  border: 1px solid $bordercolor;
}
.form_pro {
  padding-left: 25px;
}
.kuang_3 {
  width: 98%;
  height: 250px;
  background-color: $white;
  margin-left: 10px;
  margin-top: 15px;
  overflow: hidden;
  border: 1px solid $bordercolor;
  margin-bottom: 15px;
  border-radius: 5px;
}

.footer {
  margin-left: 40%;
  margin-top: 20px;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 150px;
  height: 150px;
  line-height: 100px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.form_left {
  font-weight: normal;
  margin-top: 15px;
  margin-left: 20px;
}
.wbadd {
  float: right;
  margin-right: 20px;
  text-align: center;
  margin-top: 10px;
}
.el-table {
  margin-left: 10px;
  margin-top: -25px;
  width: 95%;
}
.btn_bottom {
  margin-top: 30px;
  margin-left: 45%;
}

.f1,
.f3 {
  width: 28%;
  float: left;
}
.f2,
.f4 {
  width: 22%;
  float: left;
}
.el-input {
  width: 140px;
}
.bottom {
  width: 98%;

  background-color: $white;
  margin-left: 10px;
  overflow: hidden;
  border: 1px solid $bordercolor;
  margin-bottom: 20px;
  border-radius: 5px;
}
.div_right {
  width: 43%;
  border-radius: 5px;
  border: 1px solid $bordercolor;
  float: right;
  margin-right: 80px;
  margin-top: -20px;
  background-color: rgb(242, 242, 242);
  margin-bottom: 10px;
}
.el-table-bot {
  width: 45%;
  height: 380px;
  display: inline-block;
}
.el-form-bot {
  width: 98%;
  height: 35%;
}

#table_bot {
  width: 95%;
  margin-left: 10px;
}

.lt_1 {
  height: 60px;
  line-height: 60px;
  width: 90%;
  margin-left: 20px;
  border-bottom: 1px solid $bordercolor;
  margin-bottom: 40px;
  font-family: "微软雅黑 Bold", "微软雅黑 Regular", "微软雅黑";
  font-weight: bold;
  font-style: normal;
  font-size: 14px;
  clear: both;
}
</style>
<style >
#table_bot .el-table th {
  background: rgb(242, 242, 242);
}
</style>

